import sys
from PyQt5.QtWidgets import *
from PyQt5.QtGui import *
from PyQt5.QtCore import *

class Drawing(QWidget):
    def __init__(self,parent=None):
        super(Drawing,self).__init__(parent)
        self.setWindowTitle("绘图")
        self.resize(300,300)
        self.text='好好学习 PyQT'
    def paintEvent(self, event):
        painter=QPainter(self)
        painter.begin(self)
        #自定义绘图方法
        self.drawText(event,painter)
        painter.end()
    def drawText(self,event,qp):
        #设置画笔颜色
        qp.setPen(QColor(168,34,3))
        #设置字体
        qp.setFont(QFont('Simsun',23))
        #绘制文字
        qp.drawText(event.rect(),Qt.AlignCenter,self.text)



if __name__ == '__main__':
    app=QApplication(sys.argv)
    demo=Drawing()
    demo.show()
    sys.exit(app.exec_())